package Chinese.Education.Identify.service;

import Chinese.Education.Identify.mapper.CourseMapper;
import Chinese.Education.Identify.pojo.Course;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class CourseService {
    @Resource
    private CourseMapper courseMapper;

    public Map<String, Object> selectCourse(int page, int limit, String courseId, String courseName){
        int offset = (page - 1) * limit;
        List<Course> courses = courseMapper.selectCourse(offset, limit,courseId, courseName);
        int count = courseMapper.selectCount();
        Map<String, Object> course = new HashMap<>();
        course.put("code", 0);
        course.put("msg", "");
        course.put("count", count);
        course.put("data", courses);
        return course;
    }

    public Map<String, Object> insertCourse(Course course){
        Map<String, Object> result = new HashMap<>();
        courseMapper.insertCourse(course);
        result.put("code", 200);
        result.put("msg", "添加成功");
        result.put("data", course);
        return result;
    }
    public Map<String, Object> deleteTeacher(Course course){
        Map<String, Object> result = new HashMap<>();
        courseMapper.deleteCourse(course);
        result.put("code", 200);
        result.put("msg", "删除成功");
        result.put("data", course);
        return result;
    }

    public Map<String, Object> updateTeacher(Course course){
        Map<String, Object> result = new HashMap<>();
        courseMapper.updateCourse(course);
        result.put("code", 200);
        result.put("msg", "修改成功");
        result.put("data", course);
        return result;
    }
}
